home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / fclose.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  927b  |  48 lines

  1. /* from Dale Schumacher's dLibs */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6.  
  7. extern int __mint;
  8.  
  9. int fclose(fp)
  10.     register FILE *fp;
  11.     {
  12.     register int f;
  13.     register int error = 0;
  14.     
  15.     if(fp == NULL)
  16.         return(EOF);        /* NULL file pointer file */
  17.     f = fp->_flag;
  18.     if((f & (_IORW | _IOREAD | _IOWRT)) == 0)
  19.         return(EOF);        /* file not open! */
  20.     if(f & _IOWRT)            /* only bother flushing for write */
  21.         error = fflush(fp);
  22. #ifdef __OLD__
  23.     if(fp->_bsiz != BUFSIZ)        /* throw away non-standard buffer */
  24. #else
  25.     if(!(f & _IOMYBUF)) /* throw away non-standard buffer */
  26. #endif
  27.         {
  28.         fp->_base = NULL;
  29.         fp->_ptr = NULL;
  30.         fp->_bsiz = 0;
  31.         }
  32. #ifndef __OLD__
  33.     else
  34.         {
  35.         free(fp->_base);
  36.         fp->_base = NULL;
  37.         fp->_ptr = NULL;
  38.         fp->_bsiz = 0;
  39.         }
  40. #endif
  41.     fp->_flag = 0;            /* clear status */
  42.     if (__mint  == 0)
  43.         if(f & _IODEV)            /* leave tty's alone */
  44.             return(0);
  45.     error |= close(fp->_file);
  46.     return(error ? EOF : 0);
  47.     }
  48.